package com.bbcare.jiangmen.util;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageInfo;

import java.util.ArrayList;
import java.util.List;

/**
 * @Title		PageHelper.java
 * @Package		com.bbcare.kaili.util
 * @Description	分页工具类
 * @Author		<a href="mailto:jiangqian_java@163.com">jiang</a>
 * @Date		2023/2/16
 * @Version		V1.0 
 * @Copyright	(c) Shanghai BBcare Medical Equipment Co.,Ltd.
 */
public class PageHelper {

    public static PageInfo pageHelper(List list, Integer pageNum, Integer pageSize) {
        Page page = new Page(pageNum, pageSize);
        int total = list.size();
        page.setTotal(total);
        int startIndex = (pageNum - 1) * pageSize;
        int endIndex = Math.min(startIndex + pageSize, total);
        if (startIndex > endIndex) {
            page.addAll(new ArrayList());
            PageInfo pageInfo = new PageInfo<>(page);
            return pageInfo;
        } else {
            page.addAll(list.subList(startIndex, endIndex));
            PageInfo pageInfo = new PageInfo<>(page);
            return pageInfo;
        }
    }

}
